package Entities;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

public class ParseCsv {
	static int numberOfCourses = 0; // TODO: change to properties file?
	
	public static List<Course> parse(File file) throws IOException {
		List<Course> res = new LinkedList<Course>();
		BufferedReader bufRdr = new BufferedReader(new FileReader(file));

		String line;
		// skip first line:
		bufRdr.readLine();

		while ((line = bufRdr.readLine()) != null) {
			numberOfCourses++; // number of courses = number of lines
			String[] courseAttributes = line.split(",");
			List<Integer> adjacents = new LinkedList<Integer>();
			for (int i = 4; i < courseAttributes.length; i++) {
				adjacents.add(Integer.parseInt(courseAttributes[i]));
			}

			res.add(new Course(Integer.parseInt(courseAttributes[0]), 
							   Integer.parseInt(courseAttributes[1]), 
							   Integer.parseInt(courseAttributes[2]), 
							   Integer.parseInt(courseAttributes[3]),
							   adjacents));
		}
		return res;
	};
}
